package cn.zijitc.web;

import cn.zijitc.domain.Message;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/checkUsername")
public class checkUsername extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/text;charset=utf-8");
       resp.setCharacterEncoding("UTF-8");
        ObjectMapper mapper=new ObjectMapper();
        String username=req.getParameter("username");
        Message message=new Message();
        if (username.equals("zhangsan")){
            message.setValue("false");
        }else {
            message.setValue("true");
        }
        resp.setContentType("application/json;charset=utf-8");
        mapper.writeValue(resp.getOutputStream(),message);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
